jQuery(document).ready(function($) {
	// Tabs
	$('#tabs-wrapper .tab:not(:first), #tabs-wrapper .side-tab:not(:first)').hide();  //hide all tabs except the first tab
	
	
	// Hide/show our top-level tabs (Links and Widgets)
	$('#tabs-nav li').click(function(e) {
		$('#tabs-wrapper .tab').hide();
		$('#tabs-nav .active').removeClass('active');
		$(this).addClass('active');
		
		var clicked = $(this).find('a:first').attr('href');
		
		$('div' + clicked).slideDown();
		e.preventDefault();
	}).eq(0).addClass('active');
	
	
	// Hide/show our side tabs (social media sections - Facebook, Twitter, etc.)
	$('.side-tabs-nav li').click(function(e) {
		$('#tabs-wrapper .side-tab').hide();
		$('.side-tabs-nav .active').removeClass('active');
		$(this).addClass('active');
		
		var clicked = $(this).find('a:first').attr('href');
		
		$('div' + clicked).fadeIn();
		e.preventDefault();
	}).eq(0).addClass('active');
	
	
	//update our input value for the enable buttons
	$('.enable').toggle(function() {
		//add the value of enabled to our hidden input field and remove the disabled class so we can show our check marks
		$(this).parent().find(':input:hidden').val('enabled');
		$(this).parent().find('.enable-check').removeClass('disabled');
	}, function() {
		//add the value of disabled to our hidden input field and add the disabled class so we can hide our check marks
		$(this).parent().find(':input:hidden').val('disabled');
		$(this).parent().find('.enable-check').addClass('disabled');
	});
	
	
	//Color Picker
	$('input#twitter-widget-shell-bg, input#twitter-widget-shell-txtcolor, input#twitter-widget-tweet-bg, input#twitter-widget-tweet-color, input#twitter-widget-tweet-linkcolor').ColorPicker({
		onShow: function(colpkr) {
			$(colpkr).slideDown(500);
			return false;
		},
		onHide: function(colpkr, hex) {
			$(colpkr).slideUp(500);
			$('.selected').next().css('backgroundColor', '#' + $(this).val(hex));
			$('.selected').removeClass();
			return false;
		},
		onSubmit: function(hsb, hex, rgb, el) {
			$(el).val(hex);
			$('.colorpicker').slideUp(500);
			$('.selected').next().css('backgroundColor', '#' + hex).previous().removeClass();
		},
		onBeforeShow: function () {
			$(this).ColorPickerSetColor(this.value);
		}
	}).bind('keyup', function(){
		$(this).ColorPickerSetColor(this.value);
	}).click(function() {
		$(this).addClass('selected');
	});
	
	
	//close button
	$('#sh-wrap .close').click(function() {
		$('.updated').animate({
			opacity:0.25,
			height:'toggle'
		});
	});
});